package thread;

public class SyncDemo1 {
    static boolean success1 = false;
    static boolean success2 = false;
    public static void main(String[] args) {
        Bank bank = new Bank();

        while(true){
            Thread t1 = new Thread("zhangsan"){
                public void run() {
                    success1 = bank.getMoney(20000);
                }
            };
            Thread t2 = new Thread("lisi"){
                public void run(){
                    success2 = bank.getMoney(20000);
                }
            };
            t1.start();
            t2.start();

            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(success1&&success2){
                System.out.println("全部取款成功，出现了并发问题！");
                break;
            }else{
                bank.saveAccount(20000);
                success1 = false;
                success2 = false;
            }
        }
    }
}
